﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Asteroids
{
    class Shoot
    {
        public Texture2D tex_shoot;
        public Vector2 pos_shoot;
        private Vector2 direction;

        private float angle_direct;
        private float radians_direct_draw;

        private int speed = 10;
        public int[] quant = new int[10];
        public int aux_quant = 10;

        private bool clicked = false;

        

        public Shoot(Texture2D texshoot, Vector2 posshoot, int speedshoot, 
            float angle_direct)
        {
            this.pos_shoot = posshoot;
            this.tex_shoot = texshoot;
            this.angle_direct = angle_direct;
        }

        public void Shot(float angle_direct, KeyboardState kAtual, Vector2 posship)
        {
            // radians_direct = MathHelper.ToRadians(angle_direct);

            //if (kAtual.IsKeyDown(Keys.Space))
            //{

                if (aux_quant >= 0)
                {
                    aux_quant--;
                }
                for (int x = aux_quant; x >= 0; x--)
                {
                    radians_direct_draw = MathHelper.ToRadians(angle_direct);
                    clicked = true;
                    direction = new Vector2(((float)Math.Cos(Convert.ToDouble(MathHelper.ToRadians(angle_direct - 90))) *
                    (speed / 10)), ((float)Math.Sin(Convert.ToDouble(MathHelper.ToRadians(angle_direct - 90)))) * 
                    (speed / 10));
                    pos_shoot = posship;
                }
                
            if (pos_shoot.Y > 0 && pos_shoot.Y < 600
                    && pos_shoot.X > 0 && pos_shoot.X < 800 && clicked == true)
            {
                pos_shoot += direction ;
            }
            else
            {
                clicked = false;
            }
        }
        public void Draw(SpriteBatch spriteBratch)
        {

            spriteBratch.Begin();
            spriteBratch.Draw(tex_shoot, new Rectangle((int)pos_shoot.X, (int)pos_shoot.Y,
                (int)tex_shoot.Width, (int)tex_shoot.Height),
                new Rectangle(0, 0, tex_shoot.Width, tex_shoot.Height),
                Color.White, radians_direct_draw,
                new Vector2(tex_shoot.Width / 2, tex_shoot.Height / 2),
                SpriteEffects.None, 0f);
            spriteBratch.End();
        }

    }
}
